package com.bootdo.mall.service;

import com.bootdo.common.annotation.Log;
import com.bootdo.common.utils.Hog;
import com.bootdo.haojiangboutils.MapBuild;
import com.bootdo.mall.domain.MallOrder;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class TimeOutOrderService implements Runnable{


    public TimeOutOrderService(){
        new Thread(this).start();
    }

    @Autowired
    private MallOrderService mallOrderService;

    @Override
    public void run() {
        while (true){
            try {
                Hog.e("定时清除过期订单的线程正在执行");
                Thread.sleep(5000);
                if(null != mallOrderService){
                    List<MallOrder> list =    mallOrderService.list(MapBuild.getInstand().setKV("timeoutNumber", System.currentTimeMillis())
                            .setKV("payStatus", 0));
                    if(null != list){
                        for( MallOrder mallOrder : list){
                            mallOrderService.delOrder(mallOrder.getOrderNo());
                        }
                    }
                }
            }catch (Exception e){
                e.printStackTrace();
            }

        }
    }

}
